<?php
namespace Home\Controller;
use Home\Controller\HomeController;
class IndexController extends HomeController
{
    public function index()
    {
//        S('cateList',null);
//        S('topCate',null);
//        S('goodsList',null);
//        die;
        $this->title = "购物商城首页";
        $cate = A("Index", "Event");
        //先查询缓存,如果没有,在查询数据库
//        if(empty(S('cateList')) || empty(S('topCate')) || empty(S('goodsList'))){
        //查看所有可以显示的分类
        $cateList = $cate->queryAllCate();
        //把分类里面的顶级分类找出来,另放一个数组中
        foreach ($cateList as $key => $value) {
            if ($value['path'] == "0,") {
                $topCate[] = $cateList[$key];
                unset($cateList[$key]);
            }
        }
        //查询所有商品
        $goodsList = $cate->queryAllGoods();
//            S('cateList',$cateList,array('type'=>'file','expire'=>3));
//            S('topCate',$topCate,array('type'=>'file','expire'=>3));
//            S('goodsList',$goodsList,array('type'=>'file','expire'=>3));
//        }else{
//            $cateList = S('cateList');
//            $topCate = S('topCate');
//            $goodsList = S('goodsList');
//        }

//        echo "<pre>";
//        print_r($cateList);die;
//        print_r($topCate);
//        print_r($goodsList);die;


        $this->assign("goodsList", $goodsList);

        $this->assign("cateList", $cateList);
        $this->assign("topCate", $topCate);
//        echo "<pre>";
//        print_r($topCate);die;
        $this->display("Index:index");
    }

    //商品详情
    public function goodsDetails()
    {
        if (IS_GET) {
            $this->assign("title", "商品详情");
            $goods = A("Index", "Event");
            //根据id查询商品的所有信息
            $goodsDeatil = $goods->queryGoods();
            $this->assign("goodsDeatil", $goodsDeatil);
            //根据id查询商品的所有图片信息
            $goodsImgDeatil = $goods->queryGoodsImg();
            $this->assign("goodsImgDeatil", $goodsImgDeatil);
            //查询所有优惠券
            $couponList = $goods->queryAllCoupon();
            $this->assign("couponList", $couponList);
            //查询评价
            $queryeva = $goods->queryeva();
            $this->assign("queryeva", $queryeva);
            //评价总数
            $evatot = $goods->evatot();
            $this->assign('evatot', $evatot);
            //商品类型
            $goods_type = $goods->goods_type();
            $this->assign('goods_type', $goods_type);
            //抢购商品详情
            $goods_seckill = $goods->goods_seckill();
            $this->assign('goods_seckill', $goods_seckill);
            //团购商品详情
            $goods_group =$goods->goods_group();
            $this->assign('goods_group',$goods_group);

//            dump($goods_group);die;

            $this->display("Index/goodsDetails");
        }
    }

    //商品分类二级页面
    public function categoryDetails()
    {
        if(IS_GET){
            $indexEvent = A("Index","Event");
            //商品详情
            $res = $indexEvent->categoryDetails();
            $this->assign("goodsList",$res['goodsList']);
            $this->assign("cateList",$res['cateList']);
            $this->assign("name",$res['name']);
            $this->assign("topCateName",$res['topCateName']);
//            dump($res['goodsList']);die;
            //查询所有可以显示的分类
            $cate = $indexEvent->queryAllCate();
            $this->assign("cate",$cate);

            $this->display("Index/categoryDetails");
        }
    }
}






